﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CaiyinSoft.NetGather.Protocol;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;

namespace CaiyinSoft.NetGather.NetGatherLib.Filter
{
    public partial class FilterForm : InnerFormBase
    {
        public FilterForm()
        {
            InitializeComponent();
            this.TopLevel = false;

            if (ActiveEditor != null)
            {
                ActiveEditor.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy("C#");
            }

        }

        public HTMLFilterBase _HTMLFilter;
        public HTMLFilterBase HTMLFilter
        {
            get
            {
                if (_HTMLFilter == null)
                {
                    return null;
                }
                else
                {
                    _HTMLFilter.RunOnce = RunOnce;
                    _HTMLFilter.OutputKey = OutputKey;
                    _HTMLFilter.FilterExpression = FilterExpression;
                    return _HTMLFilter;
                }
            }
            set
            {
                _HTMLFilter = value;
                if (value != null)
                {
                    RunOnce = value.RunOnce;
                    OutputKey = value.OutputKey;
                    FilterExpression = value.FilterExpression;
                    labTitle.Text = value.FilterCaption;
                    txtDescription.Text = value.Description;
                    labExpression.Text = value.ExpressionCaption;
                    if (labExpression.Text.Length == 0)
                        txtFilterExpression.Visible = false;
                    else
                        txtFilterExpression.Visible = true;
                }
            }
        }

        public bool RunOnce
        {
            get
            {
                return chkRunOnce.Checked;
            }
            set
            {
                chkRunOnce.Checked = value;
            }
        }


        public string OutputKey
        {
            get
            {
                return txtOutKey.Text;
            }
            set
            {
                txtOutKey.Text = value;
            }
        }

        public string FilterExpression
        {
            get
            {
                return txtFilterExpression.Text;
            }
            set
            {
                txtFilterExpression.Text = value;
            }
        }

        private TextEditorControl ActiveEditor
        {
            get
            {
                return this.txtFilterExpression;
            }
        }

        private void FilterForm_Load(object sender, EventArgs e)
        {
        }
    }
}
